/**
 * @Author xieha
 * @Email xiehao35755@163.com
 * @Date 2020-02-19 22:32
 */


package com.xh.blog.user.config;

import com.xh.blog.user.api.UserInfoApi;
import feign.Contract;
import feign.Feign;
import feign.Logger;
import feign.codec.Decoder;
import feign.codec.Encoder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
 * Created by xieha on 2020-02-19.
 */

@Configuration
@Import(FeignClientsConfiguration.class)
public class FeignClientConfig {
    @Value("${user.service.host}")
    private String remoteHost;

    @Bean
    @RefreshScope
    public UserInfoApi userInfoApi(Contract contract, Decoder decoder,@Qualifier("feignEncoder") Encoder encoder) {
        System.out.print(remoteHost);
        return Feign.builder().contract(new SpringMvcContract()).encoder(encoder).decoder(decoder).logLevel(Logger.Level.FULL)
        .target(UserInfoApi.class, remoteHost);
    }

}

